<template>
  <div class="ShopClassify">
    <div class="classify">
      <div class="classify_item">
        <a 
          :class="classifyId == 0 ? 'active' : ''"
          @click="checkClassify(0)"
        >
          所有店铺
        </a>
        <a
          v-for="item in classify"
          :key="item.id"
          :class="classifyId == item.id ? 'active' : ''"
          @click="checkClassify(item)"
        >
          {{ item.name }}
        </a>
      </div>
    </div>
    <div class="sort">
      <div class="sortList">
        <a
          v-for="item in areaData"
          :key="item.id"
          :class="item.isSelected ? 'active' : ''"
          @click="checkArea(item)"
        >{{ item.title }}
        </a>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Classify",
  data() {
    return {
      classIfyData: [], // 分类
      areaData: [
        {
          // 排序
          title: "默认",
          isSelected: true,
          id: 0,
          value: "iOrder",
        },
        {
          title: "销量",
          isSelected: false,
          id: 1,
          value: "fSalePrice",
        },
        {
          title: "好评",
          isSelected: false,
          id: 2,
          value: "fSalePrice",
        },
      ],
      classifyId: "",
      areaId: "",
      classify: [],
      page: 1,
      keywords: "",
    };
  },
  mounted() {
    this.getData();
  },

  methods: {
    // 分类
    getData() {
      this.$api.home.ShopType().then((res) => {
        this.classify = res.data;
      });
    },
    checkClassify(item) {
      if (item) {
        this.classifyId = item.id;
      } else {
        this.classifyId = "";
      }
      console.log('this.classifyId', this.classifyId)
      this.$emit("getList", this.classifyId);
    },
    checkArea(item) {
      this.areaData.forEach((items) => {
        items.isSelected = false;
        if (items.id == item.id) {
          this.areaId = item.value;
          this.$set(items, "isSelected", true);
        }
      });
      this.$emit("seletedType", this.areaId);
    },
    searchThis() {
      this.$emit("getList", this.classifyId);
    },
  },
};
</script>

<style scoped lang="scss">
.ShopClassify {
  padding: 0 16.19rem;
  display: flex;
  flex-direction: column;
  .classify {
    height: 2rem;
    z-index: 100;
  }
  .classify_item {
    a {
      color: white;
      font-size: 1rem;
      line-height: 2rem;
      margin-right: 2rem;
      cursor: pointer;
      padding: 0.6rem;
      &.active {
        background: #08c19d;
      }
    }
  }

  :-webkit-input-placeholder {
    /* WebKit browsers */
    color: #acacac;
    font-size: 0.88rem;
  }

  :-moz-placeholder {
    /* Mozilla Firefox 19+ */
    color: #acacac;
    font-size: 0.88rem;
  }

  :-ms-input-placeholder {
    /* Internet Explorer 10+ */
    color: #acacac;
    font-size: 0.88rem;
  }

  .sort {
    // padding: 1.5rem 0;
    padding: 0 0 1.5rem 0;
    font-size: 1rem;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;

    .sortList {
      a {
        cursor: pointer;
        padding: 0 1rem;
        color: white;
        font-weight: 400;

        &.active {
          color: #08c19d;
        }
      }
    }
  }
}
</style>
